<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>flask</title>
    <link rel="stylesheet" href="../static/css/login.css">
</head>
<body>
    <div id="login">
        <form name= 'loginForm' action="http://127.0.0.1:5000/login" method="post" onsubmit="return validateForm()">
            <div class="title">欢迎登陆</div>
            <div class="info">
                <div class="user">
                    <span>用户名:</span>
                    <input type="text" name="username">
                </div>
                <div class="pwd">
                    <span>密码:</span>
                    <input type="password" name="password">
                </div>
                <div class="bth">
                    <input type="button" value="登录" onclick="validateAndSubmit()">
                    <input type="button" value="注册" onclick="window.location.href='http://127.0.0.1:5000/register'">
                </div>
            </div>
        </form>
    </div>
    <script>
        function validateAndSubmit() {
            let username = document.forms["loginForm"]["username"].value;
            let password = document.forms["loginForm"]["password"].value;
            if (username === "" || password === "") {
                alert("用户名和密码不能为空");
            } else {
                // 如果输入不为空，则提交表单
                document.forms["loginForm"].submit();
            }
        }
    </script>
</body>
</html>